﻿function CheckLoginID(v) {
  ajaxRead("/tools/ajax.aspx?t=chkLoginID&v=" + v, "GetSetRst(obj);");
}

function CheckIDCard(v, act) {
  if (v != "") {
    if (act == "n") {
      ajaxRead("/tools/ajax.aspx?t=chkIDCard&v=" + v + "&id=-1", "GetIDCardRst(obj);");
    } else {
      var id = document.getElementById("id").value;
      ajaxRead("/tools/ajax.aspx?t=chkIDCard&v=" + v + "&id=" + id, "GetIDCardRst(obj);");
    }
  }
}

function GetSetRst(obj) {
  var res = obj.getElementsByTagName('result');
  var rst;
  if (res[0] != null && res[0] != undefined) {
    if (res[0].childNodes.length > 1) {
      rst = res[0].childNodes[1].nodeValue;
    } else {
      rst = res[0].firstChild.nodeValue;
    }
  }
  if (rst == "1") {
    $("#chkLoginIDRst").html("该登录名已存在，请更换");
    $("#chkloginrst").val("1");
  } else {
    $("#chkLoginIDRst").html("");
    $("#chkloginrst").val("0");
  }
}

function GetIDCardRst(obj) {
  var res = obj.getElementsByTagName('result');
  var rst;
  if (res[0] != null && res[0] != undefined) {
    if (res[0].childNodes.length > 1) {
      rst = res[0].childNodes[1].nodeValue;
    } else {
      rst = res[0].firstChild.nodeValue;
    }
  }
  if (rst == "1") {
    $("#chkIDCardRst").html("该身份证号已存在，请更换");
    $("#chkidcardrst").val("1");
  } else {
    $("#chkIDCardRst").html("");
    $("#chkidcardrst").val("0");
  }
}

function CheckForm() {
  var loginid = $("#LoginIDTxt").val();
  var pwd = $("#PwdTxt").val();
  var username = $("#UserNameTxt").val();
  var area = $("#AreaSlt").val();
  var certificate = $("#CertificateSlt").val();
  var chklogin = $("#chkloginrst").val();
 // var chkidcard = $("#chkidcardrst").val();
 // var idcard = $("#IDCardTxt").val();
  var act = $("#act").val();
//  var question = document.getElementById("QuestionSlt").value;
  //  var answer = document.getElementById("AnswerTxt").value;

if (act=="n")
  var isPublic = document.getElementById("IsPublicSlt").value;

  var err = false;

  if (username != "" && area != "-1" && certificate != "-1" && chklogin != "1" && !esr && (act == "n" && isPublic != "-1") && (act == "n" && loginid != "" && pwd != "")

      || act == "u" && username != "") {
    err = false;
  } else {
    err = true;
  }

  if (err) {
    alert("必填项不能为空");
    return false;
  } else {
    return true;
  }
}

function CheckPluralForm() {
  var prefix = $("#PrefixTxt").val();
  var startno = $("#StartNoTxt").val();
  var endno = $("#EndNoTxt").val();
  var area = $("#AreaSlt").val();
  var certificate = $("#CertificateSlt").val();
//  var question = document.getElementById("QuestionSlt").value;
//  var answer = document.getElementById("AnswerTxt").value;
  var isPublic = document.getElementById("IsPublicSlt").value;

  var err = 0;
  
  if (prefix == "") {
    alert("前缀不能为空");
    err++;
    return false;
  }

  if (startno == "" || isNaN(startno)) {
    alert("起始编号不能为空或只能为数字");
    err++;
    return false;
  }

  if (endno == "" || isNaN(endno)) {
    alert("结束编号不能为空或只能为数字");
    err++;
    return false;
  }

  if (parseInt(startno) >= parseInt(endno)) {
    alert("结束编号不能小于或等于起始编号");
    err++;
    return false;
  }

  if (area == "-1") {
    alert("请选择报名机构");
    err++;
    return false;
  }

  if (certificate == "-1") {
    alert("请选择认证类别");
    err++;
    return false;
  }

//  if (question == "-1") {
//    alert("请选择忘记密码提示问题");
//    err++;
//    return false;
//  }

//  if (answer == "") {
//    alert("请填写提示问题答案");
//    err++;
//    return false;
//  }

  if (isPublic == "-1") {
    alert("请选择学员性质");
    err++;
    return false;
  }

  if (err == 0) {
    if (parseInt(endno) - parseInt(startno) > 100) {
      if (confirm("确定数量要超过100吗？")) {
        return true;
      } else {
        return false;
      }
    } else {
      return true;
    }
  } else {
    alert("信息填写错误");
    return false;
  }

}

function Step(sid) {
  var form = document.getElementById("form1");
  var rst = false;
  switch (sid) {
    case 1:
      if (document.getElementById("LoginIDTxt").value != "") {
        form.action = "?act=l";
        rst = true;
      } else {
        alert("请填写登录名");
      }
      break;
    case 2:
      if (document.getElementById("AnswerTxt").value != "") {
        form.action = "?act=q";
        rst = true;
      } else {
        alert("请填写提示问题答案");
      }
      break;
    case 3:
      var pwd = document.getElementById("NewPwdTxt").value;
      var confirmPwd = document.getElementById("ConfirmNewPwdTxt").value;
      if (pwd != "" && confirmPwd != "" && pwd == confirmPwd && pwd.length >= 6 && pwd.length <= 12 ) {
        form.action = "?act=u";
        rst = true;
      } else {
        alert("请正确填写密码");
      }
      break;
    default: break;
  }
  return rst;
}

function ce(v) {
  if (v != "") {
    if (!CheckEmail(v)) {
      document.getElementById("hint").innerHTML = "&nbsp;*Email格式错误";
      esr = true;
    }
  }
}